// ManagerRepository.java
package com.example.orderfood2.Repository;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ManagerRepository extends BaseRepository {
    
    public ManagerRepository(Context context) {
        super(context);
    }

    public boolean loginManager(String username, String password) {
        open();
        boolean result = false;
        Cursor cursor = database.query("manager", null, "username=?", 
                new String[]{username}, null, null, null);
        
        if (cursor != null) {
            try {
                if (cursor.moveToFirst()) {
                    String dbPassword = cursor.getString(cursor.getColumnIndexOrThrow("password"));
                    result = dbPassword.equals(password);
                }
            } finally {
                cursor.close();
            }
        }
        close();
        return result;
    }

    //    注册manager
    public long registerManager(String username,String password){
        open();
        ContentValues M=new ContentValues();
        M.put("username",username);
        M.put("password",password);
        long manager = database.insert("manager", null, M);
        close();
        return manager;
    }

    //    manager修改密码函数
    public int ManagerChangePassword(String username, String password) {
        open();
//        创建容器来打包数据
        ContentValues values = new ContentValues();
        values.put("username", username);
        values.put("password", password);
        int manager = database.update("manager", values, "username like ?", new String[]{username});
        close();
//        主要不是-1则成功
        return manager;
    }
    //    manager注销用户
    public void DeleteManager(String username) {
        open();
        database.delete("manager", "username =?", new String[]{username});
        close();
    }
}